var page;
var pageX = {
    actions: [],
    hasInitEdit: false,
    wfState: "view",
    showToast: true,//只拉一次横幅
    wfDesigner: null,
    cache: {},
    popCount: 0,//弹层次数
    backLock: false
}
cmp.ready(function () {

    cmp.i18n.init(_templateApprovePath + "/i18n/", "templateApproveResources", function () {
        // showFlowInfo();//首先加载就显示流程-参数信息通过url传入
        //初始化事件
        initPageData();
        initEvent();
    }, templateApproveBuildVersion);

});

function initPageData() {
    //初始化展示流程
    showFlowInfo();
}




function initEvent() {
    var flowInfoBackBtn = document.getElementById("flowInfo");
    flowInfoBackBtn.addEventListener("tap", showFlowInfo);//显示流程
    var formInfoBackBtn = document.getElementById("formInfo");
    formInfoBackBtn.addEventListener("tap", showFormInfo);//显示表单
}
//显示流程
function showFlowInfo() {
    document.getElementById("colEditWfMainBody").style.display="block";
    document.getElementById("newInputPosition").style.display="none";


    //初始化流程
    var wfParams = {
        info : {
            model : "customer",
            wfSelectorId : "colEditWfMainBody",//选择的容器
            state : "view",
            processTemplateId : "2867564509389340715"
        }
    }
    pageX.wfDesigner = new WorkFlowDesigner(wfParams);
}

//显示表单
function showFormInfo() {

    document.getElementById("newInputPosition").style.display="block";
    //设置表单显示-流程隐藏
    document.getElementById("colEditWfMainBody").style.display="none";

    var templateId = "-1333630490503134054";
   var paramData={
       templateId:templateId
   };

    $s.templateApprove.findtemplateRightId({},paramData, {
        success : function(result) {
            cmp.dialog.loading(false);
            /** 当前Affair状态校验 */
            if(result["error_msg"] && result["error_msg"]!="") {
                _alert(result["error_msg"], function() {
                    _goBack();
                });
                return;
            }


            var contentConfig = {
                "target": "newInputPosition",
                "bodyType": 20,
                "content": templateId, //3638396164344990207
                "moduleType": "1",
                "momentum": true,
                "onload": _contentInit,
                "onScroll": onContentScollTop
            }
            contentConfig.ext = {
                "isLightForm": true,
                rightId: result.formRightId,
                allowQRScan: false,
                viewState: 1,
                allowQRScan: false,
                //原样表单参数
                "openFrom": "listPending",
                "isNew": false,
                "templateId": "-1",
                "indexParam": "0",
                "contentDataId": "-1",
                "affairId": "-1", //事项id
                "isCAP4": true, //是否是cap4的模板
                "onChangeViewEvent": function(event){
                    return true;
                } //改变事件为false

            }
            SeeyonContent.init(contentConfig);
        },
        error : function(result){
            //处理异常
            templateApproveUtils.dealError(result);
        }
    });



}
function _goBack() {

    if(urlParam.fromXz || MeetingUtils.getBackURL() == "weixin"){
        //返回到外层, 微信入口逻辑，因为微信没办法返回到首页，所以这样处理， 暂时不要和else分支合并
        cmp.href.closePage();
    }else {
        //返回到外层
        cmp.href.back();
    }
}
//正文加载完成后方法
function _contentInit() {
    cmp.dialog.loading(false);


    // initSignet();


    //启动正文后面的问价
}

//注册成全局的，原表单也会调用
function onContentScollTop() {
    // LazyUtil.startLazy();
}
